package com.zzk.lanouhn.myapplication1.view;

import android.app.ActionBar;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zzk.lanouhn.myapplication1.R;

/**
 * Created by lanouhn on 16/8/27.
 */
public class SelectPicPopupWindow extends PopupWindow {

    private LinearLayout invest_pop_shu, fenxian, shuaxin, ziti;
    private RelativeLayout yejian;

    private View mPopupWindow;

    public SelectPicPopupWindow(Activity content, View.OnClickListener itemsOnclick) {
        super(content);
        LayoutInflater inflater = (LayoutInflater) content.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mPopupWindow = inflater.inflate(R.layout.popwindow_invest_detailed, null);

        invest_pop_shu = (LinearLayout) mPopupWindow.findViewById(R.id.invest_pop_shu);
        fenxian = (LinearLayout) mPopupWindow.findViewById(R.id.invest_pop_fen);
        shuaxin = (LinearLayout) mPopupWindow.findViewById(R.id.invest_pop_shua);
        ziti = (LinearLayout) mPopupWindow.findViewById(R.id.invest_pop_zi);
        yejian = (RelativeLayout) mPopupWindow.findViewById(R.id.invest_pop_ye);


        invest_pop_shu.setOnClickListener(itemsOnclick);
        fenxian.setOnClickListener(itemsOnclick);
        yejian.setOnClickListener(itemsOnclick);
        shuaxin.setOnClickListener(itemsOnclick);
        ziti.setOnClickListener(itemsOnclick);


        // 设置SelectPicPopupWindow的View
        this.setContentView(mPopupWindow);
        // 设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(ActionBar.LayoutParams.WRAP_CONTENT);
        // 设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(ActionBar.LayoutParams.WRAP_CONTENT);

        // 设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);

        // 设置SelectPicPopupWindow弹出窗体动画效果
        this.setAnimationStyle(R.style.AppTheme);

        // 实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0xb0000000);
        // 设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);

        // mMenuView添加OnTouchListener监听判断获取触屏位置如果在选择框外面则销毁弹出框
        mPopupWindow.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                int height = mPopupWindow.findViewById(R.id.invest_PopupWindow).getTop();
                int y = (int) event.getY();
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    if (y < height) {
                        dismiss();
                    }
                }
                return false;
            }
        });


    }
}
